<template>
  <div class="mnt-dialog form-container">
    <el-form ref="form" :model="formModel" label-width="120px" :rules="rules">
      <el-row style="text-align: center">
        <el-col :span="12">
          <el-form-item label="车辆VIN号:" prop="vin">
            <el-input v-model="formModel.vin" disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="报废工位代码:" prop="ulocNo">
            <el-input v-model="formModel.ulocNo" disabled/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="报废工位名称:" prop="ulocName">
            <el-input v-model="formModel.ulocName" disabled/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row style="text-align: center">
        <el-col :span="24">
          <el-form-item label="报废理由:" prop="scrapReasonDesc">
            <el-input type="textarea" v-model="formModel.scrapReasonDesc" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row class="submit-area">
      <el-col :span="24">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="handleSubmit()">确定</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>

  export default {
    name: 'VehicleScrapMnt',
    components: {

    },
    props: ['pageType', 'editData'],
    data() {
      return {
        formModel: {
          rcrdId: '',
          vin: '',
          ulocNo: '',
          ulocName: '',
          scrapReasonDesc: '',
          carStatus: '',
        },
        rules: {
        }
      }
    },
    computed: {

    },
    mounted() {
      this.init()
    },
    methods: {
      init() {
        this.$form = this.$refs.form
        const {editData, formModel} = this
        this.assignData(editData, formModel)
        this.initRules()
      },
      initRules() {
        const REQUIRED_MSG = this.CONST.REQUIRED_MSG
        this.rules = {
          vin: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
          ulocNo: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
          ulocName: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
          scrapReasonDesc: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
        }
        this.$nextTick(_ => {
          this.$form.clearValidate()
        })
      },
      handleSubmit() {
        this.$refs.form.validate(valid => {
          if (valid) {
            const { formModel } = this
            const param = { ...formModel }
            const url = '/vehicleScrapInfo/scrapVehicle'
            const tip = '车辆报废成功!'
            this.post(url, param).then(res => {
              this.$info(tip, () => {
                this.$emit('mntSuc', res)
                this.closeDialog()
              })
            })
          }
        })
      },
      closeDialog() {
        this.$parent.$emit('update:visible', false)
      },
    }
  }
</script>

<style lang="scss" scoped>

</style>
